<?php
declare (strict_types = 1);

namespace app\admin\controller;


use app\admin\model\GoodsPropValue;
use think\facade\Db;
use think\facade\Request;
use think\facade\View;

class GoodsProp
{
    public function goods_prop()
    {
        // 接参
        $vid =  Request::get('vid',[],'trim,htmlspecialchars,strip_tags');
        $pname  = Request::get('pname','','trim,htmlspecialchars,strip_tags');
        $data=[
            'vid'=>$vid,
            'pname'=>$pname,
        ];
        // 数组降维 二维数组转一维关联数组
        $list_prop_value = GoodsPropValue::getGoodsPropValue();
        // 查询
        $list =  \app\admin\model\GoodsProp::getGoodsPropList($data,input('get.'));

        // 赋值
        $empty = "<tr><td colspan='8'>暂无数据</td></tr>";
        View::assign('empty',$empty);

        // 渲染
        View::assign('list_prop_value',$list_prop_value);
        View::assign("p",$vid);
        View::assign($data );
        return View::fetch('',['list'=>$list]);
    }











    public function goods_prop2()
    {
        $pname  = Request::get('pname','','trim,htmlspecialchars,strip_tags');
        $db = Db::table('ecm_goods_prop')->field(true);
        if('' != $pname){
            $db->where('pname','like','%'.$pname.'%');
        }
        View::assign('pname ',$pname );

        $list=$db->select()->toArray();
        if(empty($list)){
            var_dump($list);
        }else{
            foreach($list as $k=>$v){
                $zhongwens=Db::table('ecm_goods_prop_value')->field('pid,prop_value')->where("vid in ({$v['pvalues']})")->select();
                $arr=[];
                foreach($zhongwens as $vv){
                    $arr[]=$vv['prop_value'];
                    $a=implode(',',$arr);
                }
                $v['a']=$a;
                $list[$k]['d']=$a;

                View::assign('arr',$arr);

            }
            View::assign('list',$list);
        }
        return  View::fetch();
    }


}